package huoye.shops.huoye.operation.presenter;


import android.util.Log;

import com.codeideology.android.lang.entity.Paging;

import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.operation.model.OrderInfo;
import huoye.shops.huoye.operation.model.SellOrder;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.ISellOrderRefreshView;


/**
 * Created by uesr on 2017/7/19.
 */

public class SellOrderPresenter extends BasePresenter<ISellOrderRefreshView> {

    private OperationService mService;

    //获取订单列表
    public void  getOrderList(int state,Paging paging){
        // view.showProcessingIndicator();
        mService.getOrderList(state,paging,new MineBaseJsonRequestCallback<SellOrder>(SellOrder.class) {

            @Override
            public void onSuccess(List<SellOrder> list) {
                super.onSuccess(list);
                view.setDataSet(list,paging);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //商家修改订单状态
    public void setOrderState(String orderId,String action,String sendType){
        //  view.showProcessingIndicator();
        mService.setOrderState(orderId,action,sendType,new MineBaseJsonRequestCallback<OrderInfo>(OrderInfo.class) {

            @Override
            public void onSuccess(OrderInfo orderInfo) {
                super.onSuccess(orderInfo);
                view.makeToast("订单操作成功!");
                view.refreshPage();

            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
                //   Log.e("testaaa",msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }




    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
